package com.orangelife.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class PicsUtil {

	public static List<Map<String, Object>> picsUrlMd(String pic,
			List<Map<String, Object>> list) {
		List<Map<String, Object>> pics = new ArrayList<Map<String, Object>>();
		String picStyle = ProConfig.getProValues("picStyle");

		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			map = list.get(i);
			if (map != null) {
				Iterator<String> iter = map.keySet().iterator();
				while (iter.hasNext()) {
					String picKeies = iter.next();
					if (picKeies.equals(pic)) {
						String picsUrl = map.get(picKeies).toString();
						if (picsUrl.contains("##")) {

							String pi[] = picsUrl.split("##");
							String tempPic = "";
							if (pi != null && pi.length > 0) {
								if (pi.length == 1) {
									tempPic = tempPic + picStyle;
								} else {
									for (int j = 0; j < pi.length - 1; j++) {
										tempPic = tempPic + (pi[j] + picStyle)+"##";;
									}
									tempPic = tempPic
											+ (pi[pi.length-1] + picStyle);
									map.put(pic, tempPic);
									break;
								}
							}
						} else {
							picsUrl = picsUrl + picStyle;
							map.put(pic, picsUrl);
						}
					}
				}
			}
			pics.add(map);
		}
		return pics;
	}

	public static String picsUrl(String pics) {
		String picStyle = ProConfig.getProValues("picStyle");
		String result = "";
		if (pics.contains("##")) {
			String pi[] = pics.split("##");
			String tempPic = "";
			if (pi != null && pi.length > 0) {
				if (pi.length == 1) {
					tempPic = tempPic + picStyle;
				} else {
					for (int j = 0; j < pi.length - 1; j++) {
						tempPic = tempPic + (pi[j] + picStyle)+"##";
					}
					tempPic = tempPic + (pi[pi.length-1] + picStyle);
				}
			}
			result = tempPic;
		} else {
			result = pics + picStyle;
		}
		return result;
	}
}
